"use strict";

var parseResponseBody = body => {
    if (body && body.length > 0) {
        var start = body.indexOf('(');
        var end = body.lastIndexOf(')');
        if (start != -1 && end != -1) {
            var datastr = body.substring(start + 1, end);
            //console.log(datastr);
            var data = JSON.parse(datastr);
            return data[0];
        }
    }
    return {};
};

module.exports.parseResponseBody = parseResponseBody;
//构造文件名，过滤掉特殊字符
module.exports.getFileName = (fileName, fileExt) => {
    //过滤特助字符
    let ch = ['\\', '/', ':', '*', '?', '\"', '<', '>', '|'];
    //let str = "\\/:*?\"<>|";
    for (let i = 0; i < ch.length; i++) {
        fileName = fileName.replace(ch[i], "_");
    }


    return fileName + "." + fileExt;
};